#include <ros/ros.h>
#include <actionlib/server/simple_action_server.h>
#include <custom_action/customAction.h>

typedef actionlib::SimpleActionServer<custom_action::customAction> Server;

void callback(const custom_action::customGoalConstPtr& goal, Server* as)
{
    ROS_INFO("-------------------------");
    ros::Rate r(1);
    custom_action::customFeedback feedback;
    ROS_INFO("开始检测 %d 个零件.", goal->requestnumber);
    // 假设检测的进度，并且按照1Hz的频率发布进度feedback 
    for (int i = 1; i <= 40; i++)
    {
            feedback.feedbacknumber = i;
            as->publishFeedback(feedback);
            r.sleep();
    }
    // 当action完成后，向客户端返回结果
    ROS_INFO("已经检测完 %d 个零件", goal->requestnumber);
    as->setSucceeded();
}

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc,argv,"custom_action_server_node");
    ros::NodeHandle nh;

    Server server(nh,"custom_action",boost::bind(&callback, _1, &server),false);

    server.start();
    ros::spin();
    return 0;
}
